import java.util.*;

class Stack {
    private Object [] data;
    private int sp;

    public Stack() {
        this(10);
    }

    public Stack(int max) {
        data = new Object[max];
        sp = 0;
    }

    public boolean isFull() {
        return (sp == data.length) ? true : false;
    }

    public boolean isEmpty() {
        return (sp == 0) ? true : false;
    }

    public int len() {
        return sp;
    }

    public Stack push(Object ... pushData) {
        if (sp + pushData.length > data.length)
            return null;

        System.arraycopy(pushData, 0, data, sp, pushData.length);
        sp += pushData.length;

        return this;
    }

    public Object pop() {
        return (isEmpty()) ? null : data[--sp];
    }

    public Object getTop() {
        return (isEmpty()) ? null : data[sp - 1];
    }
}

public class ArrayStackTest {

    static public Scanner sc = new Scanner(System.in);

    static private void _outOct(int num, int bit) {
        if (num == 0)
            return;
        _outOct(num / bit, bit);
        System.out.printf("%c", "0123456789ABCDEF".charAt(num % bit));
    }

    static public void outOct(int num, String prompt, Object ... obj) {
        System.out.printf(prompt, obj);
        if (num == 0) {
            System.out.println("0");
            return;
        } else if (num < 0) {
            num *= -1;
            System.out.printf("-");
        }
        // _outOct(num, 8);
        Stack stack = new Stack(1000);
        while (num > 0) {
            stack.push(num % 8);
            num /= 8;
        }

        while (!stack.isEmpty()) {
            System.out.printf("%d", stack.pop());
        }

        System.out.println();
    }

    static public void main(String [] args) {
        int num;

        while (true) {
            System.out.printf("请输入十进制数(-1为退出): ");
            num = sc.nextInt();
            if (num == -1)
                break;
            outOct(num, "十进制 %3d 对应的八进制是: ", num);
        }
    }
}
